Skip to content

Decommit memory on cls - #20889

Open
Leonard Hecker (lhecker) wants to merge 2 commits into
mainfrom
dev/lhecker/text-buffer-decommit
Open

Leonard Hecker (lhecker) wants to merge 2 commits into
mainfrom
dev/lhecker/text-buffer-decommit

Conversation

@lhecker

@lhecker Leonard Hecker (lhecker) commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

While the changes are complex, they are straightforward,
except for one bit: The complete refactor of ScrollRows.

The reason it became necessary is that moving the viewport to the top
during ClearScrollback may wrap the source range across the buffer's
end. VT/conhost scrolling keeps src/dst ranges within logical bounds,
where choosing the copy direction is sufficient.

For instance: Imagine we have physical rows A B C and I call
ScrollRows(2, 2, -2) then this should result in C, A, C.
However, the old logic would produce C C C, because it copies
2 (C) -> 0 (A) and then 0 (A) -> 1 (B). By the time the 2nd copy
runs, the contents of row A have already been overwritten by C.

This is the classic difference between a memmove and a scroll array.
ScrollRows has never been an actual scroll function. The name stems
more from ScrollConsoleScreenBuffer, which turn refers to historical
bit blit scrolling.

Part of #18290

Validation Steps Performed

  • cls = memory use 📉

Comment on lines +230 to +231
// Several rows may have been reset back to whitespace, akin to a mutation.
_lastMutationId++;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dustin L. Howett (@DHowett) FYI this is the only difference to the other PR. It's a bug I found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant